#各种装饰器
'''1,普通装饰器'''
#略
'''2,装饰器的嵌套
#两个装饰器,上层装饰器对下层装饰器再进行修饰
def sc(func):
    def inner():
        print(1)
        func()
        print(5)
    return inner

def xc(func):
    def inner():
        print(2)
        func()
        print(4)
    return inner

#对原函数进行装饰
@sc
@xc
#原函数
def love():
    print(3)

love()
'''
'''3,对带参数的函数进行装饰
def outer(func):
    def inner(name):
        print(f'{name}1号')
        func(name)
        print(f'{name}3号')
    return inner
@outer
#原函数
def love(name):
    print(f'{name}2号')

love('张三')
#外函内参
'''

'''4,对带有多参数的函数进行装饰
def outer(func):
    def inner(who,name,*args):
        print(f'看见了一个{who}')
        func(who,name)
        print(f'和{name}去看电影了')
    return inner
@outer
#原函数
def love(who,name):
    print(f'{who}叫{name}')

love('妹子','思思')
'''

'''5,带参数的装饰器修饰物参数的函数
def wc(name):
    print(name)
    def outer(func):
        def inner():
            print(f'我问{name}有男朋友么?')
            func()
            print(f'而且{name}打了我')
        return inner
    return outer
@wc('思思')
def love():
    print('她不告诉我')

love()
'''

'''6,对类内部的方法进行装饰
def outer(func):
    def inner(var):
        print(1)
        func(var)
        print(3)
    return inner

class Ab():
    @outer
    def love(self):
        print(2)
a=Ab()
a.love()
'''

'''7,用类装饰原函数
class Outer():
    def __call__(self,func):
        self.func=func
        return self.newinner

    def newinner(self,who):
        print(f'{who}1')
        self.func(who)
        print(f'{who}3')

@Outer()
def love(who):
    print(f'{who}2')

love('谁')
'''

'''8,用类方法装饰函数'''
class Outer():
    def newinner(func):
        Outer.func=func
        return Outer.inner

    def inner():
        print(1)
        Outer.func()
        print(3)

@Outer.newinner
def love():
    print(2)

love()






































